
// #ifdef APP-PLUS
export const postUrlPrefix="http://192.168.0.104:8080";
// #endif
// #ifdef H5
export const postUrlPrefix="/api";
// #endif

import {success,error} from '@/static/js/Message'
import qs from 'qs'

export const postJson=(url,params)=>{
	return new Promise((resolve,reject)=>{
		uni.showLoading({
			title:"正在发送请求",
			mask:true
		})
		uni.request({
			url:postUrlPrefix+url,
			header:{
			      'content-type':'application/x-www-form-urlencoded',
			},
			data:qs.stringify(params),
			method:"POST",
			success:(res)=>{
				if(res.status!==200){
					res.result=false;
					success({msg:res.data.msg||res.data.message})
					reject(new Error(res.data.msg));
				}else{
					res.result=true;
					success({msg: res.data.msg});
					resolve(res);
				}
			},
			complete:()=>{
				uni.hideLoading();
			},
			header: {
			    'Content-Type': 'application/json;charset=UTF-8'
			},
			fail:(res)=>{
				res.result=false;
				success({msg: res.data.msg})
				reject(new Error(res.data.msg));
			}
		})
	})
}

export const post=(url,params)=>{
	
	return new Promise((resolve,reject)=>{
		uni.showLoading({
			title:"正在发送请求",
			mask:true
		})
		uni.request({
			url:postUrlPrefix+url,
			data:params,
			method:"POST",
			header:{
			      'content-type':'application/x-www-form-urlencoded',
			},
			success:(res)=>{
				if(res.status!==200){
					res.result=false;
					success({msg:res.data.msg||res.data.message})
					reject(new Error(res.data.msg));
				}else{
					res.result=true;
					success({msg: res.data.msg});
					resolve(res);
				}
			},
			complete:()=>{
				uni.hideLoading();
			},
			header: {
			    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
			},
			fail:(res)=>{
				res.result=false;
				success({msg: res.data.msg})
				reject(new Error(res.data.msg));
			}
		})
	})
}

	


export const get=(url,params)=>{
	uni.showLoading({
		title:"正在发送请求",
		mask:true
	})
	return new Promise((resolve,reject)=>{
		uni.request({
			url:postUrlPrefix+url,
				data:params,
				method:"GET",
				header:{
				      'content-type':'application/x-www-form-urlencoded',
				},
				success:(res)=>{
					if(res.statusCode!==200){
						res.result=false;
						success({msg:res.data.msg})
						reject(res);
					}else{
						res.result=true;
						success({msg: res.data.msg})
						resolve(res);
					}
				},
				complete:()=>{
					uni.hideLoading();
				},
				header: {
				    'Content-Type': 'application/x-www-form-urlencoded'
				},
				fail:(res)=>{
					res.result=false;
					success({msg: res.errMsg})
					resolve(res);
				}
		})
	})
}
